import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/saas_order_meal.dart';

import '../model/order_request_data.dart';
import '../viewmodel/apply_meal_by_week_view_model.dart';

class ApplyMealByWeekPage extends BaseStatefulMvvmWidget{
  final OrderRequestData orderData;

  ApplyMealByWeekPage({required this.orderData});

  @override
  State<StatefulWidget> createState() => _ApplyMealByWeekState();

}

class _ApplyMealByWeekState extends BaseMvvmState<ApplyMealByWeekViewModel,ApplyMealByWeekPage>{
  @override
  Widget? buildLoadingContentView() {
    var info = widget.orderData;
    return Column(
      children: [
        ListView(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText('用餐信息',fontWeight: FontWeight.bold),
                SizedBox(height: 10,),
                CommonText('用餐人：${info.elderName}'),
                SizedBox(height: 10,),
                CommonText('用餐场所：${info.siteName}'),
                SizedBox(height: 10,),
                CommonText('用餐场所：${info.useTypeName}'),

              ],
            ).addToContainer(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: 10.borderRadius
              ),
              padding: EdgeInsets.symmetric(horizontal: 16,vertical: 16),
              margin: EdgeInsets.symmetric(horizontal: 16,vertical: 16)
            ),

            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText('菜品信息',fontWeight: FontWeight.bold),
                SizedBox(height: 10,),
                ...info.weekSelectFood.map((e) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      CommonText('用餐日期：${e.date}'),
                      SizedBox(height: 10,),
                      ...e.selectFood.map((meal){
                        return Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            CommonText(meal.timeSectionName),
                            SizedBox(height: 8,),
                            CommonText(meal.selectFood.map((food) => "${food.goodsName} x${food.number}").join(",")),
                            SizedBox(height: 12,)
                          ],
                        );
                      }).toList(),
                      Divider()
                    ],
                  );
                }).toList()
              ],
            ).addToContainer(
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: 10.borderRadius
                ),
                padding: EdgeInsets.symmetric(horizontal: 16,vertical: 16),
                margin: EdgeInsets.symmetric(horizontal: 16)
            ),
          ],
        ).setWeight(1),
        ElevatedButton(onPressed: (){
          viewModel.batchSubmitOrder();
        }, child: CommonText('确认结算',textColor: Colors.white),
          style: ButtonStyle(
              shape: MaterialStateProperty.all(StadiumBorder()),
              backgroundColor: MaterialStateProperty.all(SaasOrderMeal.mainColor),
              minimumSize: MaterialStateProperty.all(Size(MediaQuery.of(context).size.width-32
                  , 44))
          ),),
        SizedBox(height: 24,)
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: SaasOrderMeal.bgColor,
      appBar: AppBar(
        title: Text('下单确认'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  ApplyMealByWeekViewModel createViewModel() {
    return ApplyMealByWeekViewModel(context,orderRequestData: widget.orderData);
  }

  @override
  void onRetryClick() {
  }

  @override
  bool get touchOutDismiss => false;

  @override
  bool get backDismiss => false;
}